package server_v1;

import java.io.IOException;
import java.util.InputMismatchException;
import java.util.Scanner;
import server.Server;

/**
 * @file Server_V1.java
 * @version 0.3
 * @author James Dibble 10009689
 */
public class Server_V1 {
    static Server thisServer;
    
    public static void main(String[] args) {
        Scanner scnrInput = new Scanner(System.in);
        System.out.print("Welcome to File Server V1\n\nPort:");
        try{
            thisServer = new Server(scnrInput.nextInt(), Server.Server_Type.DESCRIPTION_SERVER);
            thisServer.start();
            System.out.println("Server running.  Press 'x' at any time to shutdown the server.");
            while(!"x".equals(scnrInput.next())){}
            try {
                thisServer.KillServer();
            } catch (IOException ex) {
                ex.printStackTrace(System.out);
                System.out.println("General Error.  Server Shutdown Abnormally.");
            }
        } catch(InputMismatchException imEx){
            imEx.printStackTrace(System.out);
            System.out.println("Port must be an integer.  Closing..");
        } catch(IOException ioEx){
            ioEx.printStackTrace(System.out);
            System.out.println("Port is probably in use.  Closing..");
        } catch(Exception ex){
            ex.printStackTrace(System.out);
            System.out.println("General Error.  Closing..");
        }
    }

}
